package lab9;

import java.util.ArrayList;
        
/**
 *     
 */

public class AlgoritmoFloyd {
    ArrayList<String> [][] ciudades;
   
    GraphMatrix graph;
    
    public AlgoritmoFloyd(GraphMatrix graph){
        this.graph=graph;
    }
    
    public GraphMatrix Floyd(){
        ciudades = new ArrayList[graph.size()][graph.size()];
        for(int i=0;i<graph.size();i++){
            for(int j=0;j<graph.size();j++){
                ciudades[i][j] = new ArrayList<String>();
            }
        }
        for (int k=0;k<graph.size();k++){
            for (int x=0;x<graph.size();x++){
                for (int y=0;y<graph.size();y++){
                    if (graph.getEdge(graph.getVertex(x),graph.getVertex(y)) > (graph.getEdge(graph.getVertex(x),graph.getVertex(k))) + graph.getEdge(graph.getVertex(k),graph.getVertex(y))){
                        ciudades[x][y].add(""+graph.getVertex(k));
                        graph.addEdge(graph.getVertex(x),graph.getVertex(y),(graph.getEdge(graph.getVertex(x),graph.getVertex(k))) + graph.getEdge(graph.getVertex(k),graph.getVertex(y)));
                    }
                }
            }
        }
        return graph;
    }
    
    public ArrayList<String> getConexion(int x, int y){
        return ciudades[x][y];
    }
}
